package org.mybatis.generator.plugins.lay.elements;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.xml.TextElement;
import util.IdUtils;

import java.util.List;

/**
 * cjianquan 2019/8/4
 */
public class LayuiMethodGenerator {
    private IntrospectedTable introspectedTable;

    private String targetModel;

    private String tableName;

    private String tableLab;

    private String code;

    private String sortOrder;

    private Integer orderCnt = 7;



    public LayuiMethodGenerator(IntrospectedTable introspectedTable,
                                String targetModel) {
        this.introspectedTable = introspectedTable;
        this.targetModel = targetModel;
        tableName = introspectedTable.getTableConfiguration().getTableName();
        tableName=toLowerCase(tableName);
        tableLab = introspectedTable.getRemarks();
        while (tableName.lastIndexOf("_") != -1) {
            int index = tableName.lastIndexOf("_");
            tableName = tableName.replaceFirst(
                    "_" + tableName.substring(index + 1, index + 2), tableName
                            .substring(index + 1, index + 2).toUpperCase());
        }
        code = targetModel + "_" + tableName;
    }

    public LayuiMethodGenerator(IntrospectedTable introspectedTable,
                                String targetModel, String sortOrder) {
        this(introspectedTable,targetModel);
        this.sortOrder = sortOrder;
    }

    public TextElement getSearchMethod(){
        StringBuilder sb = new StringBuilder();

        sb.append("<script type=\"text/html\" template id=\"TPL_"+tableName+"\">\n")
                .append("  <div class=\"layui-form\" style=\"padding-top:20px;padding-right:10px;height: 90%;\" id=\"{{d.params.elemId}}Search\">\n")
                .append("\n");

        List<IntrospectedColumn> columns = introspectedTable.getBaseColumns();

        for (IntrospectedColumn column : columns) {
            if (!column.getJavaProperty().equals("id")) {

                sb.append("    <div class=\"layui-form-item\">\n")
                        .append("      <label class=\"layui-form-label\">"+column.getRemarks()+"</label>\n")
                        .append("      <div class=\"layui-input-block\">\n");

                FullyQualifiedJavaType fqjt = column.getFullyQualifiedJavaType();

                if(fqjt.getShortName().equals("Integer") ){
                    sb.append("        <select name=\""+column.getJavaProperty()+"\"  id=\""+column.getJavaProperty()+"\" >\n" +
                            "          <option value=\"\">请选择</option>\n" +
                            "          {{#\n" +
                            "          layui.each(d.params."+column.getJavaProperty()+"Arr, function(index, item){\n" +
                            "          }}\n" +
                            "          <option value=\"{{item[0]}}\" {{d.params."+column.getJavaProperty()+"==item[0]?'selected':''}}>{{item[1]}}</option>\n" +
                            "          {{# }) }}\n" +
                            "        </select>\n");
                }else if(fqjt.getShortName().equals("Boolean")){
                    sb.append("        <select name=\""+column.getJavaProperty()+"\"  id=\""+column.getJavaProperty()+"\" >\n" +
                            "          <option value=\"\">请选择</option>\n" +
                            "          {{#\n" +
                            "          layui.each(d.params.boolArr, function(index, item){\n" +
                            "          }}\n" +
                            "          <option value=\"{{item[0]}}\" {{d.params."+column.getJavaProperty()+"==item[0]?'selected':''}}>{{item[1]}}</option>\n" +
                            "          {{# }) }}\n" +
                            "        </select>\n");
                }else if(fqjt.getShortName().equals("Date")){
                    sb.append("        <input type=\"text\" class=\"layui-input\" id=\""+column.getJavaProperty()+"-laydate-range\" autocomplete=\"off\" placeholder=\" - \">\n" +
                            "        <input type=\"hidden\" name=\""+column.getJavaProperty()+"Start\">\n" +
                            "        <input type=\"hidden\" name=\""+column.getJavaProperty()+"End\">\n");
                }else{
                    sb.append("        <input class=\"layui-input\" name=\""+column.getJavaProperty()+"\" value=\"{{d.params."+column.getJavaProperty()+"?d.params."+column.getJavaProperty()+":''}}\" autocomplete=\"off\">\n");
                }

                sb.append("      </div>\n")
                        .append("    </div>\n");
            }
        }

        sb.append("    <div class=\"layui-form-item\" >\n" +
                "      <span class=\"layui-form-label\"></span>\n" +
                "      <div class=\"layui-input-block\" style=\"margin-right:0\">\n" +
                "        <button class=\"layui-btn\" lay-submit lay-filter=\"{{d.params.elemId}}-search\" id=\"{{d.params.elemId}}-search\">\n" +
                "          <i class=\"layui-icon layui-icon-search layuiadmin-button-btn\"></i>\n" +
                "        </button>\n" +
                "        <button class=\"layui-btn layui-btn-normal\" lay-submit lay-filter=\"{{d.params.elemId}}-refresh\">\n" +
                "          <i class=\"layui-icon layui-icon-refresh-3 layuiadmin-button-btn\"></i>\n" +
                "        </button>\n" +
                "      </div>\n" +
                "    </div>\n\n\n");

        sb.append("  </div>\n" +
                "</script>\n");


        return new TextElement(sb.toString());
    }

    public TextElement getListPageMethod(){
        StringBuilder sb = new StringBuilder();

        List<IntrospectedColumn> columns = introspectedTable.getBaseColumns();

        sb.append("<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %>\n")
                .append("<%@ include file=\"/common/taglibs.jsp\"%>\n")
                .append("\n<%@taglib prefix=\"shiro\" uri=\"http://shiro.apache.org/tags\"%>\n")
                .append("<!DOCTYPE html>\n")
                .append("<html>\n")
                .append("<head>\n")
                .append("\t<meta charset=\"utf-8\">\n")
                .append("\t<title>"+tableLab+"</title>\n")
                .append("\t<meta name=\"renderer\" content=\"webkit\">\n")
                .append("\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n")
                .append("\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/layui/css/layui.css\" media=\"all\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/admin.css\" media=\"all\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/myStyle.css\" media=\"all\">\n")
//                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/dropdown.css\" media=\"all\">\n")
                .append("</head>\n")
                .append("<body>\n")
                .append("\n");

        sb.append("<div class=\"layui-fluid\" style=\"padding:0;margin:0;\">\n")
                .append("\t<div class=\"layui-card\">\n")
                .append("\n");

        StringBuilder sbSearch = new StringBuilder();
        sbSearch.append("\t\t<div class=\"layui-row layui-form\" style=\"margin-top: 10px;display: none;\">\n");

        StringBuilder colsSb = new StringBuilder("\t\t\t\t{type: 'checkbox'}\n");
        StringBuilder tplSb = new StringBuilder();
        StringBuilder dictSb = new StringBuilder();
        StringBuilder dictOptionSb = new StringBuilder();
        StringBuilder laydateSb = new StringBuilder();
        StringBuilder laydateSb_div = new StringBuilder();
        StringBuilder fieldExtend = new StringBuilder();

        boolean showFlag = false;
        StringBuilder showTpl = new StringBuilder();

        StringBuilder reset_field = new StringBuilder("{");
        for (IntrospectedColumn column : columns) {
            String javaProperty = column.getJavaProperty();
            String remarks = column.getRemarks();
            FullyQualifiedJavaType fqjt = column.getFullyQualifiedJavaType();
            String shortName = fqjt.getShortName();//.equals("Integer")

            reset_field.append("\n\t\t\t\t"+javaProperty+":null,");

            sbSearch.append("\t\t\t<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md3\">\n")
                    .append("\t\t\t\t<label class=\"layui-form-label\">"+remarks+"</label>\n")
                    .append("\t\t\t\t<div class=\"layui-input-block\">\n");
            if(shortName.equals("Integer") || shortName.equals("Boolean")){

                colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:130,templet:"+javaProperty+"Tpl}\n");
                tplSb.append("\t\tvar "+javaProperty+"Tpl = function(d){\n")
                        .append("\t\t\tvar html = dict.showName(\"dict_"+tableName+"_"+javaProperty+"\",d."+javaProperty+");\n")
                        .append("\t\t\treturn html;\n")
                        .append("\t\t};\n");

                sbSearch.append("\t\t\t\t\t<select name=\""+javaProperty+"\"  id=\""+javaProperty+"\" >\n")
                        .append("\t\t\t\t\t</select>\n");

                dictSb.append("\t\tdict.setSelect(\""+javaProperty+"\",\"dict_"+tableName+"_"+javaProperty+"\");\n");
                dictOptionSb.append("                var "+javaProperty+"Arr = dict.options(\"dict_"+tableName+"_"+javaProperty+"\");\n");
                fieldExtend.append("                            "+javaProperty+"Arr:"+javaProperty+"Arr,\n");

            }else if(shortName.equals("Date")){

                colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:160,templet:"+javaProperty+"Tpl}\n");
                tplSb.append("\t\tvar "+javaProperty+"Tpl = function(d){\n")
                        .append("\t\t\tif(d."+javaProperty+"){\n")
                        .append("\t\t\t\treturn util.toDateString(d."+javaProperty+",'yyyy-MM-dd');\n")
                        .append("\t\t\t}\n")
                        .append("\t\t\treturn '';\n")
                        .append("\t\t};\n");
                sbSearch.append("\t\t\t\t\t<input type=\"text\" class=\"layui-input\" id=\""+javaProperty+"-laydate-range\" autocomplete=\"off\" placeholder=\" - \">\n")
                        .append("\t\t\t\t\t<input type=\"hidden\" name=\""+javaProperty+"Start\">\n")
                        .append("\t\t\t\t\t<input type=\"hidden\" name=\""+javaProperty+"End\">\n");
                laydateSb.append("\t\tadmin.renderDateForSearch(\""+javaProperty+"\")\n");
                laydateSb_div.append("                                admin.renderDateForSearch(\""+javaProperty+"\",search_field);\n");
            }else{
                if(showFlag==false){
                    showFlag = true;
                    colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:130,templet:"+javaProperty+"Tpl }\n");
                    showTpl.append("\t\tvar "+javaProperty+"Tpl = function (d) {\n" +
                            "            var html = '<a style=\"color:#1E9FFF\" href=\"javascript:void(0);\" lay-event=\"showRec\" >'+d."+javaProperty+"+'</a>';\n" +
                            "            return html;\n" +
                            "\t\t\t\n" +
                            "        }\n");
                }else{
                    colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:130 }\n");
                }
//                colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:130 }\n");

                sbSearch.append("\t\t\t\t\t<input class=\"layui-input\" name=\""+javaProperty+"\" autocomplete=\"off\">\n");
            }


            sbSearch.append("\t\t\t\t</div>\n")
                    .append("\t\t\t</div>\n");

        }
        reset_field.append("}");
        colsSb.append("\t\t\t\t,{title:'操作', toolbar: '#'+elemId+'-bar', width:90,fixed:'right'}\n");

        sbSearch.append("\t\t\t<div class=\"layui-col-xs6 layui-col-sm3 layui-col-md3\"  >\n" +
                "\t\t\t\t<button class=\"layui-btn\" lay-submit lay-filter=\""+tableName+"Table-search\" style=\"margin-left: 5px;\">\n" +
                "\t\t\t\t\t<i class=\"layui-icon layui-icon-search layuiadmin-button-btn\"></i>\n" +
                "\t\t\t\t</button>\n" +
                "\t\t\t\t<button class=\"layui-btn layui-btn-normal\" lay-submit lay-filter=\""+tableName+"Table-refresh\">\n" +
                "\t\t\t\t\t<i class=\"layui-icon layui-icon-refresh-3 layuiadmin-button-btn\"></i>\n" +
                "\t\t\t\t</button>\n" +
                "\t\t\t</div>\n")
                .append("\t\t</div>\n");


        sb.append("\n")
                .append(sbSearch.toString())
                .append("\t\t<div class=\"layui-row\" style=\"width: 100%;overflow-x: auto;\">\n")
                .append("\t\t\t<table class=\"layui-hide\" id=\""+tableName+"Table\" lay-filter=\""+tableName+"Table\"></table>\n")
                .append("\t\t</div>\n")
                .append("\t\t<script type=\"text/html\" id=\""+tableName+"Table-toolbar\">\n")
                .append("\t\t\t<div class=\"layui-btn-container\">\n")
                .append("\t\t\t\t<shiro:hasPermission name=\""+tableName+":add\">\n")
                .append("\t\t\t\t\t<button class=\"layui-btn layui-btn-sm\" data-type=\"addRec\">添加</button>\n")
                .append("\t\t\t\t</shiro:hasPermission>\n")
                .append("\t\t\t\t<shiro:hasPermission name=\""+tableName+":del\">\n")
                .append("\t\t\t\t\t<button class=\"layui-btn layui-btn-sm layui-btn-danger\" data-type=\"delRec\">删除</button>\n")
                .append("\t\t\t\t</shiro:hasPermission>\n")
                .append("\t\t\t</div>\n")
                .append("\t\t</script>\n")
                .append("\n")
                .append("\t\t<script type=\"text/html\" id=\""+tableName+"Table-bar\">\n")
                .append("\t\t\t<shiro:hasPermission name=\""+tableName+":edit\">\n")
                .append("\t\t\t\t<a class=\"layui-btn layui-btn-xs\" lay-event=\"editRec\">编辑</a>\n")
                .append("\t\t\t</shiro:hasPermission>\n")
                .append("\t\t</script>\n")
                .append("\n")
                .append("\t</div>\n")
                .append("</div>\n\n")
                .append("<script src=\"${ctxLayui}/layuiadmin/layui/layui.js\"></script>\n")
                .append("<script>\n")
                .append("\tlayui.config({\n")
                .append("\t\tbase: '${ctxLayui}/layuiadmin/'\n")
                .append("\t}).extend({\n")
                .append("\t\tindex: 'lib/index'\n")
                .append("\t}).use(['index', 'table','dict','laydate','util'], function(){\n")
                .append("\t\tvar $ = layui.$,table = layui.table,form = layui.form;\n")
                .append("\t\tvar dict = layui.dict;\n")
                .append("\t\tvar laydate = layui.laydate;\n")
                .append("\t\tvar admin = layui.admin;\n")
                .append("\t\tvar util = layui.util;\n")
//                .append("\t\tvar dropdown = layui.dropdown;\n")
                .append(dictSb.toString())
                .append(laydateSb.toString())
                .append(tplSb.toString())
                .append(showTpl.toString())
                .append("\n")
                .append("\t\tvar reset_field = "+reset_field.toString()+";\n")
                .append("\t\tvar search_field = { };\n")
                .append("\t\tvar where = {};\n")
                .append("\t\tvar elemId = \""+tableName+"Table\";\n")
                .append("\t\tvar tableIns = table.render({\n")
                .append("\t\t\telem:'#'+elemId\n")
                .append("\t\t\t,url: ctx+'/"+targetModel+"/"+tableName+"/query'\n")
                .append("\t\t\t,where:where\n")
                .append("\t\t\t,error:admin.error\n")
                .append("\t\t\t,cellMinWidth: 80\n")
//                .append("\t\t\t,width:"+((colsSize+3)*100)+"\n")
                .append("\t\t\t,toolbar: '#'+elemId+'-toolbar'\n")
                .append("            ,defaultToolbar: [{\n" +
                        "                title: '条件过滤' //标题\n" +
                        "                ,layEvent: 'searchDiv' //事件名，用于 toolbar 事件中使用\n" +
                        "                ,icon: 'layui-icon-search' //图标类名\n" +
                        "            },\n" +
                        "                'filter', 'print', 'exports']\n")
                .append("\t\t\t,cols: [[\n")
                .append(colsSb.toString())
                .append("\t\t\t]]\n")
                .append("\t\t\t,page: true\n")
                .append("\t\t\t,limit: 10\n")
                .append("\t\t\t,limits: layui.setter.limits\n")
                .append("\t\t\t,height: 'full-1'\n")
                .append("\t\t\t,done: function(res, curr, count){\n")
//                .append("\t\t\t\tvar _tableData = res;\n" +
//                        "                dropdown.suite();\n" +
//                        "                for (var i = 0; i < _tableData.data.length; i++) {\n" +
//                        "                    var row = _tableData.data[i];\n" +
//                        "                    mapData.set(\"\"+row.id,row);\n" +
//                        "                    dropdown.onFilter(\"ft\" + row.id, function (event) {\n" +
//                        "                        var arr = event.split(\"_\");\n" +
//                        "                        active[arr[0]].call({},{key:arr[1]})\n" +
//                        "                    });\n" +
//                        "                }\n")
                .append("\t\t\t}\n")
                .append("\t\t});\n")
                .append("\t\tvar active = {\n")
                .append("\t\t\tshowRec:function (obj) {\n")
                .append("\t\t\t\twindow.formData = null;\n")
                .append("\t\t\t\tvar dialog = layer.open({\n")
                .append("\t\t\t\t\ttype: 2\n")
                .append("\t\t\t\t\t,title: '"+tableLab+"'\n")
                .append("\t\t\t\t\t,content: '"+tableName+"Show.jsp'\n")
                .append("\t\t\t\t\t,maxmin: true\n")
                .append("\t\t\t\t\t,area: layui.setter.area_percent\n")
                .append("\t\t\t\t\t,offset: 't'\n")
                .append("\t\t\t\t\t,btn: ['关闭']\n")
                .append("\t\t\t\t\t,btnAlign: 'c'\n")
                .append("\t\t\t\t\t,success:function(layero,index){\n")
                .append("\t\t\t\t\t\twindow.formData = obj.data;\n")
                .append("\t\t\t\t\t}\n")
                .append("\t\t\t\t});\n")
                .append("\t\t\t\tlayer.full(dialog)\n")
                .append("\t\t\t},\n")
                .append("\t\t\taddRec: function(){\n")
                .append("\t\t\t\twindow.formData = {};\n")
                .append("\t\t\t\tvar dialog = layer.open({\n")
                .append("\t\t\t\t\ttype: 2\n")
                .append("\t\t\t\t\t,title: '"+tableLab+"'\n")
                .append("\t\t\t\t\t,content: '"+tableName+"Form.jsp'\n")
                .append("\t\t\t\t\t,maxmin: true\n")
                .append("\t\t\t\t\t,area: layui.setter.area_percent\n")
                .append("\t\t\t\t\t,offset: 't'\n")
                .append("\t\t\t\t\t,btn: ['确定', '取消']\n")
                .append("\t\t\t\t\t,btnAlign: 'c'\n")
                .append("\t\t\t\t\t,yes: function(index, layero){\n")
                .append("\t\t\t\t\t\tvar iframeWindow = window['layui-layer-iframe'+ index]\n")
                .append("\t\t\t\t\t\t\t,submit = layero.find('iframe').contents().find(\"#"+tableName+"Form-submit\");\n")
                .append("\t\t\t\t\t\tiframeWindow.layui.form.on('submit("+tableName+"Form-submit)', function(data){\n")
                .append("\t\t\t\t\t\t\tvar field = data.field;\n")
                .append("\t\t\t\t\t\t\tvar rtn = admin.syncReq(ctx+\"/"+targetModel+"/"+tableName+"/add\",field);\n")
                .append("\t\t\t\t\t\t\tif(rtn && rtn.code==0){\n")
                .append("\t\t\t\t\t\t\t\tlayer.close(index);\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作成功');\n")
                .append("\t\t\t\t\t\t\t\tsetTimeout(function () { active.reload() },0);\n")
                .append("\t\t\t\t\t\t\t}else{\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作失败');\n")
                .append("\t\t\t\t\t\t\t}\n")
                .append("\t\t\t\t\t\t});\n")
                .append("\t\t\t\t\t\tsubmit.trigger('click');\n")
                .append("\t\t\t\t\t}\n")
                .append("\t\t\t\t});\n")
                .append("\t\t\t\tlayer.full(dialog)\n")
                .append("\t\t\t},\n")
                .append("\t\t\teditRec:function(obj){\n")
                .append("\t\t\t\tvar rec = obj.data;\n")
                .append("\t\t\t\twindow.formData = rec;\n")
                .append("\t\t\t\tvar dialog = layer.open({\n")
                .append("\t\t\t\t\ttype: 2\n")
                .append("\t\t\t\t\t,title: '"+tableLab+"'\n")
                .append("\t\t\t\t\t,content: '"+tableName+"Form.jsp'\n")
                .append("\t\t\t\t\t,maxmin: true\n")
                .append("\t\t\t\t\t,area: layui.setter.area_percent\n")
                .append("\t\t\t\t\t,offset: 't'\n")
                .append("\t\t\t\t\t,btn: ['确定', '取消']\n")
                .append("\t\t\t\t\t,btnAlign: 'c'\n")
                /*.append("\t\t\t\t\t,success:function(layero,index){\n")
                .append("\t\t\t\t\t\tvar body = layer.getChildFrame('body', index);\n")
                .append("\t\t\t\t\t\tvar data = obj.data;\n")
                .append("\t\t\t\t\t\twindow.formData = data;\n")
                .append("\t\t\t\t\t\t$.each(data,function(item){\n")
                .append("\t\t\t\t\t\t\tbody.find(\"[name=\"+item+\"]\").val(data[item]);\n")
                .append("\t\t\t\t\t\t});\n")
                .append("\t\t\t\t\t}\n")*/
                .append("\t\t\t\t\t,yes: function(index, layero){\n")
                .append("\t\t\t\t\t\tvar iframeWindow = window['layui-layer-iframe'+ index]\n")
                .append("\t\t\t\t\t\t\t,submit = layero.find('iframe').contents().find(\"#"+tableName+"Form-submit\");\n")
                .append("\t\t\t\t\t\tiframeWindow.layui.form.on('submit("+tableName+"Form-submit)', function(data){\n")
                .append("\t\t\t\t\t\t\tvar field = data.field; \n")
                .append("\t\t\t\t\t\t\tfield.id = rec.id;\n")
                .append("\t\t\t\t\t\t\tvar rtn = admin.syncReq(ctx+\"/"+targetModel+"/"+tableName+"/modify\",field);\n")
                .append("\t\t\t\t\t\t\tif(rtn && rtn.code==0){\n")
                .append("\t\t\t\t\t\t\t\tlayer.close(index);\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作成功');\n")
                .append("\t\t\t\t\t\t\t\tsetTimeout(function () { active.reload(); },0);\n")
//                .append("\t\t\t\t\t\t\t\tform.render();\n")
                .append("\t\t\t\t\t\t\t}else{\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作失败');\n")
                .append("\t\t\t\t\t\t\t}\n")
                .append("\t\t\t\t\t\t});\n")
                .append("\t\t\t\t\t\tsubmit.trigger('click');\n")
                .append("\t\t\t\t\t}\n")
                .append("\t\t\t\t});\n")
                .append("\t\t\t\tlayer.full(dialog)\n")
                .append("\t\t\t},\n")
                .append("\t\t\tdelRec:function (obj) {\n" +
                        "                var idArr = [];\n" +
                        "                var tipMsg = '';\n" +
                        "\t\t\t    if(obj){\n" +
                        "                    idArr.push(obj.data.id);\n" +
                        "                    tipMsg = '确定删除该记录？'\n" +
                        "\t\t\t\t}else{\n" +
                        "                    var checkStatus = table.checkStatus(elemId)\n" +
                        "                    var recs = checkStatus.data;\n" +
                        "                    if(!recs || recs.length<=0){\n" +
                        "                        layer.msg('请至少选择一条记录');\n" +
                        "                        return;\n" +
                        "                    }\n" +
                        "                    for(var i=0;i<recs.length;i++){\n" +
                        "                        var rec = recs[i];\n" +
                        "                        idArr.push(rec.id);\n" +
                        "                    }\n" +
                        "                    tipMsg = '确定删除'+recs.length+'条记录?';\n" +
                        "\t\t\t\t}\n" +
                        "\n" +
                        "\t\t\t\tlayer.confirm(tipMsg, function(index){\n" +
                        "\t\t\t\t\tvar rtn = admin.syncReq(ctx+\"/"+targetModel+"/"+tableName+"/deleteByBatch\",{ids:idArr.join(\",\")});\n" +
                        "\t\t\t\t\tif(rtn && rtn.code==0){\n" +
                        "\t\t\t\t\t\tlayer.msg('操作成功');\n" +
                        "\t\t\t\t\t\tsetTimeout(function () { active.reload() },0);\n" +
                        "\t\t\t\t\t}else{\n" +
                        "\t\t\t\t\t\tlayer.msg('操作失败');\n" +
                        "\t\t\t\t\t}\n" +
                        "\t\t\t\t});\n" +
                        "\t\t\t},\n")
                .append("\t\t\treload: function(){\n")
                .append("\t\t\t\ttableIns.reload();\n")
                .append("\t\t\t},\n")
                .append("            searchDiv: function(){\n" +
                        dictOptionSb.toString()+
                        "                top.layui.admin.popupRight({\n" +
                        "                    id: 'LAY_'+elemId+'PopupLayer'\n" +
                        "                    ,area: '350px'\n" +
                        "                    ,success: function(layero,index){\n" +
                        "                        top.layui.view(this.id).render('"+targetModel+"/"+tableName+"Search',$.extend({elemId:elemId},search_field,{\n" +
                        fieldExtend.toString() +
                        "\t\t\t\t\t\t})).done(\n" +
                        "                            function () {\n" +
                        "                                top.layui.form.render();\n" +
                        laydateSb_div.toString()+
                        "                            }\n" +
                        "                        );\n" +
                        "                    }\n" +
                        "                });\n" +
                        "            },\n")
                .append("\t\t};\n")
                .append("\t\ttable.on('toolbar('+elemId+')', function(obj){\n")
                .append("            switch(obj.event){\n" +
                        "                case 'searchDiv':\n" +
                        "                    active.searchDiv()\n" +
                        "                    break;\n" +
                        "            };\n")
                .append("\t\t});\n")
                .append("\t\ttable.on('tool('+elemId+')', function(obj){\n")
                .append("\t\t\tswitch(obj.event){\n")
                .append("\t\t\t\tcase 'editRec':\n")
                .append("\t\t\t\t\tactive.editRec(obj);\n")
                .append("\t\t\t\t\tbreak;\n")
                .append("\t\t\t\tcase 'showRec':\n")
                .append("\t\t\t\t\tactive.showRec(obj);\n")
                .append("\t\t\t\t\tbreak;\n")
                .append("\t\t\t}\n")
                .append("\t\t});\n")
                .append("        /*form.on('submit('+elemId+'-search)', function(data){\n" +
                        "            var field = data.field;\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "        });\n" +
                        "        form.on('submit('+elemId+'-refresh)', function(data){\n" +
                        "            $(':input').not(':button, :submit, :reset').val('').removeAttr('selected').removeAttr('checked');\n" +
                        "            form.render();\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},reset_field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "        });*/\n" +
                        "\n" +
                        "        top.layui.form.on('submit('+elemId+'-search)', function(data){\n" +
                        "            var field = data.field;\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "            search_field = field;\n" +
                        "            top.layui.layer.close(top.layui.admin.popup.index);\n" +
                        "        });\n" +
                        "\n" +
                        "        top.layui.form.on('submit('+elemId+'-refresh)', function(data){\n" +
                        "            top.layui.$(':input').not(':button, :submit, :reset').val('').removeAttr('selected').removeAttr('checked')\n" +
                        "            search_field = {};\n" +
                        "            top.layui.form.render();\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},reset_field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "        });\n\n")
                .append("        $(\"body\").on('click','.layui-btn-container .layui-btn', function(){\n" +
                        "            var type = $(this).data('type');\n" +
                        "            active[type] ? active[type].call(this) : '';\n" +
                        "        });\n\n")
                .append("        admin.tableRowCheckToggle();\n\n")
                .append("\t});\n")
                .append("</script>\n")
                .append("</body>\n")
                .append("</html>\n");

        return new TextElement(sb.toString());

    }


    public TextElement getListPageMethod1(){
        StringBuilder sb = new StringBuilder();

        List<IntrospectedColumn> columns = introspectedTable.getBaseColumns();

        sb.append("<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %>\n")
                .append("<%@ include file=\"/common/taglibs.jsp\"%>")
                .append("\n<%@taglib prefix=\"shiro\" uri=\"http://shiro.apache.org/tags\"%>\n")
                .append("<!DOCTYPE html>\n")
                .append("<html>\n")
                .append("<head>\n")
                .append("\t<meta charset=\"utf-8\">\n")
                .append("\t<title>"+tableLab+"</title>\n")
                .append("\t<meta name=\"renderer\" content=\"webkit\">\n")
                .append("\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n")
                .append("\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/layui/css/layui.css\" media=\"all\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/admin.css\" media=\"all\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/myStyle.css\" media=\"all\">\n")
//                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/dropdown.css\" media=\"all\">\n")
                .append("</head>\n")
                .append("<body>\n")
                .append("\n")
//                .append("<div class=\"layui-card layadmin-header\">\n")
//                .append("\t<div class=\"layui-breadcrumb\" lay-filter=\"breadcrumb\">\n")
//                .append("\t\t<!--<a lay-href=\"\">xx管理</a>-->\n")
//                .append("\t\t<a><cite>"+tableLab+"</cite></a>\n")
//                .append("\t</div>\n")
//                .append("</div>\n")
                .append("\n")
                .append("<div class=\"layui-fluid\" style=\"padding:0;margin:0;\">\n")
                .append("\t<div class=\"layui-card\">\n");


        StringBuilder sbSearch = new StringBuilder();
        sbSearch.append("")
                .append("\t\t<div class=\"layui-form layui-card-header layuiadmin-card-header-auto layui-hide\" style=\"padding:10px 0 5px 0;\">\n")
                .append("\t\t\t<div class=\"layui-form-item\">\n");


        StringBuilder colsSb = new StringBuilder("\t\t\t\t{type: 'checkbox'}\n");
        StringBuilder tplSb = new StringBuilder();
        StringBuilder dictSb = new StringBuilder();
        StringBuilder dictOptionSb = new StringBuilder();
        StringBuilder laydateSb = new StringBuilder();
        StringBuilder laydateSb_div = new StringBuilder();
        StringBuilder fieldExtend = new StringBuilder();

        StringBuilder reset_field = new StringBuilder("{");
        for (IntrospectedColumn column : columns) {
            String javaProperty = column.getJavaProperty();
            String remarks = column.getRemarks();
            FullyQualifiedJavaType fqjt = column.getFullyQualifiedJavaType();
            String shortName = fqjt.getShortName();//.equals("Integer")

            reset_field.append("\n\t\t\t\t"+javaProperty+":null,");

            sbSearch.append("\t\t\t\t<div class=\"layui-inline layui-inline-31\">\n")
                    .append("\t\t\t\t\t<label class=\"layui-form-label\">"+remarks+"</label>\n")
                    .append("\t\t\t\t\t<div class=\"layui-input-block\">\n");
            if(shortName.equals("Integer") || shortName.equals("Boolean")){

                colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:130,templet:tpl"+toUpperCase(javaProperty)+"}\n");
                tplSb.append("\t\tvar tpl"+toUpperCase(javaProperty)+" = function(d){\n")
                        .append("\t\t\tvar html = dict.showName(\"dict_"+tableName+"_"+javaProperty+"\",d."+javaProperty+");\n")
                        .append("\t\t\treturn html;\n")
                        .append("\t\t};\n");

                sbSearch.append("\t\t\t\t\t\t<select name=\""+javaProperty+"\"  id=\""+javaProperty+"\" >\n")
                        .append("\t\t\t\t\t\t</select>\n");

                dictSb.append("\t\tdict.setSelect(\""+javaProperty+"\",\"dict_"+tableName+"_"+javaProperty+"\");\n");
                dictOptionSb.append("                var "+javaProperty+"Arr = dict.options(\"dict_"+tableName+"_"+javaProperty+"\");\n");
                fieldExtend.append("                            "+javaProperty+"Arr:"+javaProperty+"Arr,\n");

            }else if(shortName.equals("Date")){

                colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:160,templet:tpl"+toUpperCase(javaProperty)+"}\n");
                tplSb.append("\t\tvar tpl"+toUpperCase(javaProperty)+" = function(d){\n")
                        .append("\t\t\tif(d."+javaProperty+"){\n")
                        .append("\t\t\t\treturn util.toDateString(d."+javaProperty+",'yyyy-MM-dd');\n")
                        .append("\t\t\t}\n")
                        .append("\t\t\treturn '';\n")
                        .append("\t\t};\n");
                sbSearch.append("\t\t\t\t\t\t<input type=\"text\" class=\"layui-input\" id=\""+javaProperty+"-laydate-range\" autocomplete=\"off\" placeholder=\" - \">\n")
                        .append("\t\t\t\t\t\t<input type=\"hidden\" name=\""+javaProperty+"Start\">\n")
                        .append("\t\t\t\t\t\t<input type=\"hidden\" name=\""+javaProperty+"End\">\n");
                laydateSb.append("\t\tadmin.renderDateForSearch(\""+javaProperty+"\")\n");
                laydateSb_div.append("                                admin.renderDateForSearch(\""+javaProperty+"\",search_field);\n");
            }else{
                colsSb.append("\t\t\t\t,{field:'"+javaProperty+"', title: '"+remarks+"', align: 'center',width:130 }\n");

                sbSearch.append("\t\t\t\t\t\t<input class=\"layui-input\" name=\""+javaProperty+"\" autocomplete=\"off\">\n");
            }


            sbSearch.append("\t\t\t\t\t</div>\n")
                    .append("\t\t\t\t</div>\n");

        }
        reset_field.append("}");
        colsSb.append("\t\t\t\t,{title:'操作', toolbar: '#'+elemId+'-bar', width:90,fixed:'right'}\n");

        sbSearch.append("\t\t\t\t<div class=\"layui-inline\" style=\"margin-right:0\">\n")
                .append("\t\t\t\t\t<button class=\"layui-btn\" lay-submit lay-filter=\""+tableName+"Table-search\">\n")
                .append("\t\t\t\t\t\t<i class=\"layui-icon layui-icon-search layuiadmin-button-btn\"></i>\n")
                .append("\t\t\t\t\t</button>\n")
                .append("\t\t\t\t</div>\n")
                .append("\t\t\t\t<div class=\"layui-inline\" style=\"margin-right:0\">\n")
                .append("\t\t\t\t\t<button class=\"layui-btn layui-btn-normal\" lay-submit lay-filter=\""+tableName+"Table-refresh\">\n")
                .append("\t\t\t\t\t\t<i class=\"layui-icon layui-icon-refresh-3 layuiadmin-button-btn\"></i>\n")
                .append("\t\t\t\t\t</button>\n")
                .append("\t\t\t\t</div>\n")
                .append("\t\t\t</div>\n")
                .append("\t\t</div>\n");

        sb.append("\n")
                .append(sbSearch.toString())
                .append("\t\t<div class=\"layui-card-body\" style=\"padding:0;\">\n")
                .append("\t\t\t<div style=\"width: 100%;overflow-x: auto;\">\n")
                .append("\t\t\t\t<table class=\"layui-hide\" id=\""+tableName+"Table\" lay-filter=\""+tableName+"Table\"></table>\n")
                .append("\t\t\t</div>\n")
                .append("\t\t\t<script type=\"text/html\" id=\""+tableName+"Table-toolbar\">\n")
                .append("\t\t\t\t<div class=\"layui-btn-container\">\n")
                .append("\t\t\t\t\t<shiro:hasPermission name=\""+tableName+":add\">\n")
                .append("\t\t\t\t\t\t<button class=\"layui-btn layui-btn-sm\" data-type=\"addRec\">添加</button>\n")
                .append("\t\t\t\t\t</shiro:hasPermission>\n")
                .append("\t\t\t\t\t<shiro:hasPermission name=\""+tableName+":del\">\n")
                .append("\t\t\t\t\t\t<button class=\"layui-btn layui-btn-sm layui-btn-danger\" data-type=\"delRec\">删除</button>\n")
                .append("\t\t\t\t\t</shiro:hasPermission>\n")
                .append("\t\t\t\t</div>\n")
                .append("\t\t\t</script>\n")
                .append("\n")
                /*.append("\t\t\t<script type=\"text/html\" id=\""+tableName+"Table-bar\">\n" +
                        "\t\t\t\t<button class=\"layui-btn layui-btn-xs\" lay-filter=\"ft{{d.id}}\" lay-dropdown=\"{align:'left', menus:\n" +
                                "\t\t\t\t[\n" +
                                "\t\t\t\t{txt: '查看', event:'showRec_{{d.id}}'},\n" +
                                "\t\t\t\t{txt: '修改', event:'editRec_{{d.id}}'},\n" +
                                "\t\t\t\t{txt: '删除', event:'delRec_{{d.id}}'},\n" +
                                "\t\t\t\t]}\">\n" +
                                "\t\t\t\t\t<span>操作</span>\n" +
                                "\t\t\t\t\t<i class=\"layui-icon layui-icon-triangle-d\"></i>\n" +
                                "\t\t\t\t</button>\n"+
                        "\t\t\t</script>\n")*/
                .append("\t\t\t<script type=\"text/html\" id=\""+tableName+"Table-bar\">\n")
                .append("\t\t\t\t<shiro:hasPermission name=\""+tableName+":edit\">\n")
                .append("\t\t\t\t\t<a class=\"layui-btn layui-btn-xs\" lay-event=\"editRec\">编辑</a>\n")
                .append("\t\t\t\t</shiro:hasPermission>\n")
                .append("\t\t\t\t<a class=\"layui-btn layui-btn-xs layui-btn-normal\" lay-event=\"showRec\">查看</a>\n")
                .append("\t\t\t</script>\n")
                .append("\n")
                .append("\t\t</div>\n")
                .append("\t</div>\n")
                .append("</div>\n")
                .append("<script src=\"${ctxLayui}/layuiadmin/layui/layui.js\"></script>\n")
                .append("<script>\n")
                .append("\tlayui.config({\n")
                .append("\t\tbase: '${ctxLayui}/layuiadmin/'\n")
                .append("\t}).extend({\n")
                .append("\t\tindex: 'lib/index'\n")
                .append("\t}).use(['index', 'table','dict','laydate','util'], function(){\n")
                .append("\t\tvar $ = layui.$,table = layui.table,form = layui.form;\n")
                .append("\t\tvar dict = layui.dict;\n")
                .append("\t\tvar laydate = layui.laydate;\n")
                .append("\t\tvar admin = layui.admin;\n")
                .append("\t\tvar util = layui.util;\n")
//                .append("\t\tvar dropdown = layui.dropdown;\n")
                .append(dictSb.toString())
                .append(laydateSb.toString())
                .append(tplSb.toString())
                .append("\n")
                .append("\t\tvar reset_field = "+reset_field.toString()+";\n")
                .append("\t\tvar search_field = { };\n")
                .append("\t\tvar where = {};\n")
                .append("\t\tvar elemId = \""+tableName+"Table\";\n")
                .append("\t\tvar tableIns = table.render({\n")
                .append("\t\t\telem:'#'+elemId\n")
                .append("\t\t\t,url: ctx+'/"+targetModel+"/"+tableName+"/query'\n")
                .append("\t\t\t,where:where\n")
                .append("\t\t\t,error:admin.error\n")
                .append("\t\t\t,cellMinWidth: 80\n")
//                .append("\t\t\t,width:"+((colsSize+3)*100)+"\n")
                .append("\t\t\t,toolbar: '#'+elemId+'-toolbar'\n")
                .append("            ,defaultToolbar: [{\n" +
                        "                title: '条件过滤' //标题\n" +
                        "                ,layEvent: 'searchDiv' //事件名，用于 toolbar 事件中使用\n" +
                        "                ,icon: 'layui-icon-search' //图标类名\n" +
                        "            },\n" +
                        "                'filter', 'print', 'exports']\n")
                .append("\t\t\t,cols: [[\n")
                .append(colsSb.toString())
                .append("\t\t\t]]\n")
                .append("\t\t\t,page: true\n")
                .append("\t\t\t,limit: 10\n")
                .append("\t\t\t,limits: layui.setter.limits\n")
                .append("\t\t\t,height: 'full-1'\n")
                .append("\t\t\t,done: function(res, curr, count){\n")
//                .append("\t\t\t\tvar _tableData = res;\n" +
//                        "                dropdown.suite();\n" +
//                        "                for (var i = 0; i < _tableData.data.length; i++) {\n" +
//                        "                    var row = _tableData.data[i];\n" +
//                        "                    mapData.set(\"\"+row.id,row);\n" +
//                        "                    dropdown.onFilter(\"ft\" + row.id, function (event) {\n" +
//                        "                        var arr = event.split(\"_\");\n" +
//                        "                        active[arr[0]].call({},{key:arr[1]})\n" +
//                        "                    });\n" +
//                        "                }\n")
                .append("\t\t\t}\n")
                .append("\t\t});\n")
                .append("\t\tvar active = {\n")
                .append("\t\t\tshowRec:function (obj) {\n")
                .append("\t\t\t\twindow.formData = null;\n")
                .append("\t\t\t\tvar dialog = layer.open({\n")
                .append("\t\t\t\t\ttype: 2\n")
                .append("\t\t\t\t\t,title: '"+tableLab+"'\n")
                .append("\t\t\t\t\t,content: '"+tableName+"Show.jsp'\n")
                .append("\t\t\t\t\t,maxmin: true\n")
                .append("\t\t\t\t\t,area: layui.setter.area_percent\n")
                .append("\t\t\t\t\t,offset: 't'\n")
                .append("\t\t\t\t\t,btn: ['关闭']\n")
                .append("\t\t\t\t\t,btnAlign: 'c'\n")
                .append("\t\t\t\t\t,success:function(layero,index){\n")
                .append("\t\t\t\t\t\twindow.formData = obj.data;\n")
                .append("\t\t\t\t\t}\n")
                .append("\t\t\t\t});\n")
                .append("\t\t\t\tlayer.full(dialog)\n")
                .append("\t\t\t},\n")
                .append("\t\t\taddRec: function(){\n")
                .append("\t\t\t\twindow.formData = {};\n")
                .append("\t\t\t\tvar dialog = layer.open({\n")
                .append("\t\t\t\t\ttype: 2\n")
                .append("\t\t\t\t\t,title: '"+tableLab+"'\n")
                .append("\t\t\t\t\t,content: '"+tableName+"Form.jsp'\n")
                .append("\t\t\t\t\t,maxmin: true\n")
                .append("\t\t\t\t\t,area: layui.setter.area_percent\n")
                .append("\t\t\t\t\t,offset: 't'\n")
                .append("\t\t\t\t\t,btn: ['确定', '取消']\n")
                .append("\t\t\t\t\t,btnAlign: 'c'\n")
                .append("\t\t\t\t\t,yes: function(index, layero){\n")
                .append("\t\t\t\t\t\tvar iframeWindow = window['layui-layer-iframe'+ index]\n")
                .append("\t\t\t\t\t\t\t,submit = layero.find('iframe').contents().find(\"#"+tableName+"Form-submit\");\n")
                .append("\t\t\t\t\t\tiframeWindow.layui.form.on('submit("+tableName+"Form-submit)', function(data){\n")
                .append("\t\t\t\t\t\t\tvar field = data.field;\n")
                .append("\t\t\t\t\t\t\tvar rtn = admin.syncReq(ctx+\"/"+targetModel+"/"+tableName+"/add\",field);\n")
                .append("\t\t\t\t\t\t\tif(rtn && rtn.code==0){\n")
                .append("\t\t\t\t\t\t\t\tlayer.close(index);\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作成功');\n")
                .append("\t\t\t\t\t\t\t\tsetTimeout(function () { active.reload() },0);\n")
                .append("\t\t\t\t\t\t\t}else{\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作失败');\n")
                .append("\t\t\t\t\t\t\t}\n")
                .append("\t\t\t\t\t\t});\n")
                .append("\t\t\t\t\t\tsubmit.trigger('click');\n")
                .append("\t\t\t\t\t}\n")
                .append("\t\t\t\t});\n")
                .append("\t\t\t\tlayer.full(dialog)\n")
                .append("\t\t\t},\n")
                .append("\t\t\teditRec:function(obj){\n")
                .append("\t\t\t\tvar rec = obj.data;\n")
                .append("\t\t\t\twindow.formData = rec;\n")
                .append("\t\t\t\tvar dialog = layer.open({\n")
                .append("\t\t\t\t\ttype: 2\n")
                .append("\t\t\t\t\t,title: '"+tableLab+"'\n")
                .append("\t\t\t\t\t,content: '"+tableName+"Form.jsp'\n")
                .append("\t\t\t\t\t,maxmin: true\n")
                .append("\t\t\t\t\t,area: layui.setter.area_percent\n")
                .append("\t\t\t\t\t,offset: 't'\n")
                .append("\t\t\t\t\t,btn: ['确定', '取消']\n")
                .append("\t\t\t\t\t,btnAlign: 'c'\n")
                /*.append("\t\t\t\t\t,success:function(layero,index){\n")
                .append("\t\t\t\t\t\tvar body = layer.getChildFrame('body', index);\n")
                .append("\t\t\t\t\t\tvar data = obj.data;\n")
                .append("\t\t\t\t\t\twindow.formData = data;\n")
                .append("\t\t\t\t\t\t$.each(data,function(item){\n")
                .append("\t\t\t\t\t\t\tbody.find(\"[name=\"+item+\"]\").val(data[item]);\n")
                .append("\t\t\t\t\t\t});\n")
                .append("\t\t\t\t\t}\n")*/
                .append("\t\t\t\t\t,yes: function(index, layero){\n")
                .append("\t\t\t\t\t\tvar iframeWindow = window['layui-layer-iframe'+ index]\n")
                .append("\t\t\t\t\t\t\t,submit = layero.find('iframe').contents().find(\"#"+tableName+"Form-submit\");\n")
                .append("\t\t\t\t\t\tiframeWindow.layui.form.on('submit("+tableName+"Form-submit)', function(data){\n")
                .append("\t\t\t\t\t\t\tvar field = data.field; \n")
                .append("\t\t\t\t\t\t\tfield.id = rec.id;\n")
                .append("\t\t\t\t\t\t\tvar rtn = admin.syncReq(ctx+\"/"+targetModel+"/"+tableName+"/modify\",field);\n")
                .append("\t\t\t\t\t\t\tif(rtn && rtn.code==0){\n")
                .append("\t\t\t\t\t\t\t\tlayer.close(index);\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作成功');\n")
                .append("\t\t\t\t\t\t\t\tsetTimeout(function () { active.reload(); },0);\n")
//                .append("\t\t\t\t\t\t\t\tform.render();\n")
                .append("\t\t\t\t\t\t\t}else{\n")
                .append("\t\t\t\t\t\t\t\tlayer.msg('操作失败');\n")
                .append("\t\t\t\t\t\t\t}\n")
                .append("\t\t\t\t\t\t});\n")
                .append("\t\t\t\t\t\tsubmit.trigger('click');\n")
                .append("\t\t\t\t\t}\n")
                .append("\t\t\t\t});\n")
                .append("\t\t\t\tlayer.full(dialog)\n")
                .append("\t\t\t},\n")
                .append("\t\t\tdelRec:function (obj) {\n" +
                        "                var idArr = [];\n" +
                        "                var tipMsg = '';\n" +
                        "\t\t\t    if(obj){\n" +
                        "                    idArr.push(obj.data.id);\n" +
                        "                    tipMsg = '确定删除该记录？'\n" +
                        "\t\t\t\t}else{\n" +
                        "                    var checkStatus = table.checkStatus(elemId)\n" +
                        "                    var recs = checkStatus.data;\n" +
                        "                    if(!recs || recs.length<=0){\n" +
                        "                        layer.msg('请至少选择一条记录');\n" +
                        "                        return;\n" +
                        "                    }\n" +
                        "                    for(var i=0;i<recs.length;i++){\n" +
                        "                        var rec = recs[i];\n" +
                        "                        idArr.push(rec.id);\n" +
                        "                    }\n" +
                        "                    tipMsg = '确定删除'+recs.length+'条记录?';\n" +
                        "\t\t\t\t}\n" +
                        "\n" +
                        "\t\t\t\tlayer.confirm(tipMsg, function(index){\n" +
                        "\t\t\t\t\tvar rtn = admin.syncReq(ctx+\"/"+targetModel+"/"+tableName+"/deleteByBatch\",{ids:idArr.join(\",\")});\n" +
                        "\t\t\t\t\tif(rtn && rtn.code==0){\n" +
                        "\t\t\t\t\t\tlayer.msg('操作成功');\n" +
                        "\t\t\t\t\t\tsetTimeout(function () { active.reload() },0);\n" +
                        "\t\t\t\t\t}else{\n" +
                        "\t\t\t\t\t\tlayer.msg('操作失败');\n" +
                        "\t\t\t\t\t}\n" +
                        "\t\t\t\t});\n" +
                        "\t\t\t},\n")
                .append("\t\t\treload: function(){\n")
                .append("\t\t\t\ttableIns.reload();\n")
                .append("\t\t\t},\n")
                .append("            searchDiv: function(){\n" +
                        dictOptionSb.toString()+
                        "                top.layui.admin.popupRight({\n" +
                        "                    id: 'LAY_'+elemId+'PopupLayer'\n" +
                        "                    ,area: '350px'\n" +
                        "                    ,success: function(layero,index){\n" +
                        "                        top.layui.view(this.id).render('"+targetModel+"/"+tableName+"Search',$.extend({elemId:elemId},search_field,{\n" +
                        fieldExtend.toString() +
                        "\t\t\t\t\t\t})).done(\n" +
                        "                            function () {\n" +
                        "                                top.layui.form.render();\n" +
                        laydateSb_div.toString()+
                        "                            }\n" +
                        "                        );\n" +
                        "                    }\n" +
                        "                });\n" +
                        "            },\n")
                .append("\t\t};\n")
                .append("\t\ttable.on('toolbar('+elemId+')', function(obj){\n")
                .append("            switch(obj.event){\n" +
                        "                case 'searchDiv':\n" +
                        "                    active.searchDiv()\n" +
                        "                    break;\n" +
                        "            };\n")
                .append("\t\t});\n")
                .append("\t\ttable.on('tool('+elemId+')', function(obj){\n")
                .append("\t\t\tswitch(obj.event){\n")
                .append("\t\t\t\tcase 'editRec':\n")
                .append("\t\t\t\t\tactive.editRec(obj);\n")
                .append("\t\t\t\t\tbreak;\n")
                .append("\t\t\t\tcase 'showRec':\n")
                .append("\t\t\t\t\tactive.showRec(obj);\n")
                .append("\t\t\t\t\tbreak;\n")
                .append("\t\t\t}\n")
                .append("\t\t});\n")
                .append("        /*form.on('submit('+elemId+'-search)', function(data){\n" +
                        "            var field = data.field;\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "        });\n" +
                        "        form.on('submit('+elemId+'-refresh)', function(data){\n" +
                        "            $(':input').not(':button, :submit, :reset').val('').removeAttr('selected').removeAttr('checked');\n" +
                        "            form.render();\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},reset_field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "        });*/\n" +
                        "\n" +
                        "        top.layui.form.on('submit('+elemId+'-search)', function(data){\n" +
                        "            var field = data.field;\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "            search_field = field;\n" +
                        "            top.layui.layer.close(top.layui.admin.popup.index);\n" +
                        "        });\n" +
                        "\n" +
                        "        top.layui.form.on('submit('+elemId+'-refresh)', function(data){\n" +
                        "            top.layui.$(':input').not(':button, :submit, :reset').val('').removeAttr('selected').removeAttr('checked')\n" +
                        "            search_field = {};\n" +
                        "            top.layui.form.render();\n" +
                        "            table.reload(elemId, {\n" +
                        "                where: $.extend({},reset_field,where)\n" +
                        "                ,page:{curr:1}\n"+
                        "            });\n" +
                        "        });\n\n")
                .append("        $(\"body\").on('click','.layui-btn-container .layui-btn', function(){\n" +
                        "            var type = $(this).data('type');\n" +
                        "            active[type] ? active[type].call(this) : '';\n" +
                        "        });\n\n")
                .append("        admin.tableRowCheckToggle();\n\n")
                .append("\t});\n")
                .append("</script>\n")
                .append("</body>\n")
                .append("</html>\n");

        return new TextElement(sb.toString());
    }

    public TextElement getEditDialogMethod() {
        StringBuilder sb = new StringBuilder();

        sb.append("<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %>\n")
                .append("<%@ include file=\"/common/taglibs.jsp\"%>")
                .append("\n<%@taglib prefix=\"shiro\" uri=\"http://shiro.apache.org/tags\"%>\n")
                .append("<!DOCTYPE html>\n")
                .append("<html >\n")
                .append("<head>\n")
                .append("\t<meta charset=\"utf-8\">\n")
                .append("\t<title>"+tableLab+"</title>\n")
                .append("\t<meta name=\"renderer\" content=\"webkit\">\n")
                .append("\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n")
                .append("\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/layui/css/layui.css\" media=\"all\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/myStyle.css\" media=\"all\">\n")
                .append("</head>\n")
                .append("<body>\n")
                .append("<div class=\"layui-form layui-row\" lay-filter=\""+tableName+"Form\" id=\""+tableName+"Form\" style=\"padding: 20px 10px 0 0;\">\n")
                .append("\n");

        List<IntrospectedColumn> columns = introspectedTable.getBaseColumns();
        StringBuilder dictSb = new StringBuilder();
        StringBuilder dateSb = new StringBuilder();
        for (IntrospectedColumn column : columns) {
            if (!column.getJavaProperty().equals("id")) {

                sb.append("\t<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md6\" >\n")
                        .append("\t\t<label class=\"layui-form-label\">"+column.getRemarks()+"<span style=\"color:red\">*</span></label>\n")
                        .append("\t\t<div class=\"layui-input-block\">\n");

                FullyQualifiedJavaType fqjt = column.getFullyQualifiedJavaType();
                System.out.println("column.getJavaProperty()="+column.getJavaProperty()+",fqjt.getShortName()="+fqjt.getShortName());
                if(fqjt.getShortName().equals("Integer") || fqjt.getShortName().equals("Boolean")){
                    sb.append("\t\t\t<select name=\""+column.getJavaProperty()+"\" lay-verify=\"required\" id=\""+column.getJavaProperty()+"\" lay-filter=\""+column.getJavaProperty()+"\">\n")
                            .append("\t\t\t</select>\n");
                    dictSb.append("\t\tdict.setSelect(\""+column.getJavaProperty()+"\",\"dict_"+tableName+"_"+column.getJavaProperty()+"\",formData."+column.getJavaProperty()+");\n");
                }else if(fqjt.getShortName().equals("Boolean")){
                    sb.append("\t\t\t<input type=\"checkbox\" name=\""+column.getJavaProperty()+"\" lay-filter=\"form-switch\" lay-skin=\"switch\" lay-text=\"是|否\">\n");

                    dictSb.append("\t\tdict.setSwitch(\""+column.getJavaProperty()+"\",formData?(formData."+column.getJavaProperty()+"?formData."+column.getJavaProperty()+":0):0)\n");
                }else if(fqjt.getShortName().equals("Date")){
                    sb.append("\t\t\t<input type=\"text\" class=\"layui-input\" name=\""+column.getJavaProperty()+"\" id=\""+column.getJavaProperty()+"-laydate\" autocomplete=\"off\" placeholder=\"\">\n");
                    dateSb.append("        admin.renderDate(\""+column.getJavaProperty()+"\",formData);\n");
                }else{
                    sb.append("\t\t\t<input type=\"text\" name=\""+column.getJavaProperty()+"\" lay-verify=\"required\" placeholder=\"\" autocomplete=\"off\" class=\"layui-input\">\n");
                }

                sb.append("\t\t</div>\n")
                        .append("\t</div>\n");
            }
        }

        sb.append("\n")
                .append("\t<div class=\"layui-form-item layui-hide\">\n")
                .append("\t\t<input type=\"button\" lay-submit lay-filter=\""+tableName+"Form-submit\" id=\""+tableName+"Form-submit\" value=\"添加\">\n")
//                .append("\t\t<input type=\"button\" lay-submit lay-filter=\""+tableName+"Form-edit\" id=\""+tableName+"Form-edit\" value=\"修改\">\n")
                .append("\t</div>\n")
                .append("</div>\n\n")
                .append("<script src=\"${ctxLayui}/layuiadmin/layui/layui.js\"></script>\n")
                .append("<script>\n")
                .append("\tlayui.config({\n")
                .append("\t\tbase: '${ctxLayui}/layuiadmin/'\n")
                .append("\t}).extend({\n")
                .append("\t\tindex: 'lib/index'\n")
                .append("\t}).use(['index', 'form','dict','laydate','util'], function(){\n")
                .append("\t\tvar $ = layui.$ ,form = layui.form;\n")
                .append("\t\tvar dict = layui.dict;\n")
                .append("\t\tvar laydate = layui.laydate;\n")
                .append("\t\tvar util = layui.util;\n")
                .append("\t\tvar admin = layui.admin;\n")
                .append("\t\tvar formData = window.parent.formData;\n")
                .append("\t\tvar id = formData?formData.id:'';\n")
                .append("\t\tif(!id){\n")
                .append("\t\t\t//todo\n")
                .append("\t\t}\n")
                .append("\t\tform.val(\""+tableName+"Form\",$.extend({},formData))\n")
                .append(dictSb)
                .append(dateSb)
                .append("        form.verify({\n" +
                        "            v_email:admin.v_email,\n" +
                        "            v_phone:admin.v_phone,\n" +
                        "            v_url:admin.v_url,\n" +
                        "            v_number:admin.v_number,\n" +
                        "            v_date:admin.v_date,\n" +
                        "        })\n")
                .append("\t})\n")
                .append("</script>\n")
                .append("</body>\n")
                .append("</html>\n");

        return new TextElement(sb.toString());
    }


    public TextElement getShowDialogMethod() {
        StringBuilder sb = new StringBuilder();

        sb.append("<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %>\n")
                .append("<%@ include file=\"/common/taglibs.jsp\"%>")
                .append("\n<%@taglib prefix=\"shiro\" uri=\"http://shiro.apache.org/tags\"%>\n")
                .append("<!DOCTYPE html>\n")
                .append("<html >\n")
                .append("<head>\n")
                .append("\t<meta charset=\"utf-8\">\n")
                .append("\t<title>"+tableLab+"</title>\n")
                .append("\t<meta name=\"renderer\" content=\"webkit\">\n")
                .append("\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n")
                .append("\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/layui/css/layui.css\" media=\"all\">\n")
                .append("\t<link rel=\"stylesheet\" href=\"${ctxLayui}/layuiadmin/style/myStyle.css\" media=\"all\">\n")
                .append("</head>\n")
                .append("<body>\n")
                .append("<div class=\"layui-form layui-row\" lay-filter=\""+tableName+"Form\" id=\""+tableName+"Form\" style=\"padding: 20px 10px 0 0;\">\n")
                .append("\n");

        List<IntrospectedColumn> columns = introspectedTable.getBaseColumns();
        StringBuilder dictSb = new StringBuilder();
        for (IntrospectedColumn column : columns) {
            if (!column.getJavaProperty().equals("id")) {

                sb.append("\t<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md6\" >\n")
                        .append("\t\t<label class=\"layui-form-label\">"+column.getRemarks()+"</label>\n")
                        .append("\t\t<div class=\"layui-input-block\">\n");

                FullyQualifiedJavaType fqjt = column.getFullyQualifiedJavaType();

                if(fqjt.getShortName().equals("Integer") || fqjt.getShortName().equals("Boolean")){
                    sb.append("\t\t\t<div class=\"layui-form-mid "+column.getJavaProperty()+"Str\"></div>\n");
                    dictSb.append("\t\tformData."+column.getJavaProperty()+"Str = dict.showName(\"dict_"+tableName+"_"+column.getJavaProperty()+"\",formData."+column.getJavaProperty()+");\n");
                }else if(fqjt.getShortName().equals("Date")){
                    sb.append("\t\t\t<div class=\"layui-form-mid "+column.getJavaProperty()+"Str\"></div>\n");
                    dictSb.append("\t\tformData."+column.getJavaProperty()+"Str = formData."+column.getJavaProperty()+"?util.toDateString(formData."+column.getJavaProperty()+",'yyyy-MM-dd'):'';\n");
                }else{
                    sb.append("\t\t\t<div class=\"layui-form-mid "+column.getJavaProperty()+"\"></div>\n");
                }

                sb.append("\t\t</div>\n")
                        .append("\t</div>\n");
            }
        }

        sb.append("\n")
                .append("</div>\n\n")
                .append("<script src=\"${ctxLayui}/layuiadmin/layui/layui.js\"></script>\n")
                .append("<script>\n")
                .append("\tlayui.config({\n")
                .append("\t\tbase: '${ctxLayui}/layuiadmin/'\n")
                .append("\t}).extend({\n")
                .append("\t\tindex: 'lib/index'\n")
                .append("\t}).use(['index', 'form','dict','laytpl','util'], function(){\n")
                .append("\t\tvar $ = layui.$ ,form = layui.form;\n")
                .append("\t\tvar dict = layui.dict;\n")
                .append("\t\tvar laytpl = layui.laytpl;\n")
                .append("\t\tvar util = layui.util;\n")
                .append("\t\tvar formData = window.parent.formData;\n")
                .append(dictSb)
                .append("\t\tfor(var key in formData){\n" +
                        "\t\t    if(key && formData[key]){\n" +
                        "\t\t        $(\"#"+tableName+"Form .\"+key).html(formData[key])\n" +
                        "\t\t\t}\n" +
                        "\t\t}\n")
                .append("\t})\n")
                .append("</script>\n")
                .append("</body>\n")
                .append("</html>\n");

        return new TextElement(sb.toString());
    }

    protected String toLowerCase(String tableName) {
        StringBuilder sb = new StringBuilder(tableName);
        sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
        return sb.toString();
    }

    /**
     * BaseUsers to baseUsers
     *
     * @param tableName
     * @return
     */
    protected String toUpperCase(String tableName) {
        StringBuilder sb = new StringBuilder(tableName);
        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
        return sb.toString();
    }

    public TextElement getSqlMethod(String pack) {
        StringBuilder sb = new StringBuilder();

        Long id = IdUtils.id();
        sb.append("INSERT INTO `SysMenu`(`id`, `name`, `title`, `icon`, `path`, `perms`, `component`, `redirect`, `parentId`, `sortOrder`,  `type`, `cacheFlag`,`status`, `createTime`, `modifyTime`, `remark`) VALUES ("+id+", '"+tableName+"List', '"+tableLab+"', NULL, '"+pack+"/"+tableName+"List.jsp', NULL, NULL, NULL, 123456, 50, 2, 1, 1,now(),now(), NULL);\n");
        sb.append("INSERT INTO `SysMenu`(`id`, `name`, `title`, `icon`, `path`, `perms`, `component`, `redirect`, `parentId`, `sortOrder`,  `type`, `cacheFlag`,`status`, `createTime`, `modifyTime`, `remark`) VALUES ("+IdUtils.id()+", NULL, '添加', '', '', '"+tableName+":add', NULL, NULL, "+id+", 10, 3, NULL, 1,now(),now(), NULL);\n");
        sb.append("INSERT INTO `SysMenu`(`id`, `name`, `title`, `icon`, `path`, `perms`, `component`, `redirect`, `parentId`, `sortOrder`,  `type`, `cacheFlag`,`status`, `createTime`, `modifyTime`, `remark`) VALUES ("+IdUtils.id()+", NULL, '删除', '', '', '"+tableName+":del', NULL, NULL, "+id+", 20, 3, NULL, 1,now(),now(), NULL);\n");
        sb.append("INSERT INTO `SysMenu`(`id`, `name`, `title`, `icon`, `path`, `perms`, `component`, `redirect`, `parentId`, `sortOrder`,  `type`, `cacheFlag`,`status`, `createTime`, `modifyTime`, `remark`) VALUES ("+IdUtils.id()+", NULL, '编辑', '', '', '"+tableName+":edit', NULL, NULL, "+id+", 30, 3, NULL, 1,now(),now(), NULL);\n");
        return new TextElement(sb.toString());
    }

    public TextElement getSqlMethodManage(String pack) {
        StringBuilder sb = new StringBuilder();

        Long id = IdUtils.id();
        sb.append("INSERT INTO `manage_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+id+", NULL, '"+tableLab+"', NULL, 123456, 3, '"+pack+"/"+tableName+"List.jsp', '', '', 15, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `manage_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '添加', NULL, "+id+", 4, null, null, '"+tableName+":add', 5, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `manage_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '删除', NULL, "+id+", 4, null, null, '"+tableName+":del', 10, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `manage_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '编辑', NULL, "+id+", 4, null, null, '"+tableName+":edit', 15, 1, NULL, now(), now());\n");
        return new TextElement(sb.toString());
    }

    public TextElement getSqlMethodAgent(String pack) {
        StringBuilder sb = new StringBuilder();

        Long id = IdUtils.id();
        sb.append("INSERT INTO `agent_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+id+", NULL, '"+tableLab+"', NULL, 123456, 3, '"+pack+"/"+tableName+"List.jsp', '', '', 15, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `agent_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '添加', NULL, "+id+", 4, null, null, '"+tableName+":add', 5, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `agent_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '删除', NULL, "+id+", 4, null, null, '"+tableName+":del', 10, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `agent_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '编辑', NULL, "+id+", 4, null, null, '"+tableName+":edit', 15, 1, NULL, now(), now());\n");
        return new TextElement(sb.toString());
    }

    public TextElement getSqlMethodBusiness(String pack) {
        StringBuilder sb = new StringBuilder();

        Long id = IdUtils.id();
        sb.append("INSERT INTO `business_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+id+", NULL, '"+tableLab+"', NULL, 123456, 3, '"+pack+"/"+tableName+"List.jsp', '', '', "+orderCnt+", 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `business_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '添加', NULL, "+id+", 4, null, null, '"+tableName+":add', 5, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `business_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '删除', NULL, "+id+", 4, null, null, '"+tableName+":del', 10, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `business_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '编辑', NULL, "+id+", 4, null, null, '"+tableName+":edit', 15, 1, NULL, now(), now());\n");
        orderCnt=orderCnt+5;
        return new TextElement(sb.toString());
    }

    public TextElement getSqlMethodAdmin(String pack) {
        StringBuilder sb = new StringBuilder();

        Long id = IdUtils.id();
        sb.append("INSERT INTO `admin_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+id+", NULL, '"+tableLab+"', NULL, 123456, 3, '"+pack+"/"+tableName+"List.jsp', '', '', "+orderCnt+", 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `admin_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '添加', NULL, "+id+", 4, null, null, '"+tableName+":add', 5, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `admin_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '删除', NULL, "+id+", 4, null, null, '"+tableName+":del', 10, 1, NULL, now(), now());\n");
        sb.append("INSERT INTO `admin_menu`(`id`, `platform`, `name`, `code`, `parentId`, `type`, `url`, `icon`, `perm`, `sortOrder`, `status`, `remark`, `createTime`, `modifyTime`) VALUES ("+IdUtils.id()+", NULL, '编辑', NULL, "+id+", 4, null, null, '"+tableName+":edit', 15, 1, NULL, now(), now());\n");
        orderCnt=orderCnt+5;
        return new TextElement(sb.toString());
    }
}
